﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Train_ViewCertificate : System.Web.UI.Page
{
    private Srvtools.WebDataSet WMaster;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ViewState["tiaojian"] = "终止有效日期";

            InitializeComponent();
            Master.DataSource = WMaster;

            this.DSelYearMonth1.SelectYear = DateTime.Now.Year.ToString();
            this.DSelYearMonth1.SelectMonth = DateTime.Now.Month.ToString();


            MasterPage_MasterPage mpg = (MasterPage_MasterPage)this.Page.Master;
            mpg.HelpHref = "~/Help/Train/证书查询.htm";
            mpg.PageName = "证书查询";
            mpg.PicUrl = "";
            mpg.IntiBar();
        } 
    }

    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Train_ViewCertificate));
        this.WMaster = new Srvtools.WebDataSet();
        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).BeginInit();
        // 
        // WMaster
        // 
        this.WMaster.Active = true;
        this.WMaster.AlwaysClose = false;
        this.WMaster.DeleteIncomplete = true;
        this.WMaster.Guid = null;
        this.WMaster.LastKeyValues = null;
        this.WMaster.Locale = new System.Globalization.CultureInfo("zh-CN");
        this.WMaster.PacketRecords = 100;
        this.WMaster.Position = -1;
        string where = "1=1";
        if (ViewState["depId"] != null)
            where += " AND department.departmentid=" + ViewState["depId"].ToString();
        if (ViewState["empid"] != null)
            where += " AND Employees.EmpName like '%" + ViewState["empid"].ToString() + "%' ";

        if (ViewState["tiaojian"] == "终止有效日期")
        {
            if (ViewState["dates"] != null)
                where += " AND datediff(day,'" + ViewState["dates"].ToString() + "',CertEDate)<=60";
            else
                where += " AND datediff(day,getdate(),CertEDate)<=60";
        }
        else
        {
            if (ViewState["dates"] != null)
                where += " AND datediff(day,'" + ViewState["dates"].ToString() + "',CertRDate)<=60";
            else
                where += " AND datediff(day,getdate(),CertRDate)<=60";
        }
        this.WMaster.SetWhere(where);
        this.WMaster.RemoteName = "Train.View_Certificate";
        this.WMaster.ServerModify = false;

        ((System.ComponentModel.ISupportInitialize)(this.WMaster)).EndInit();

    }

    protected void btnQuery_Click(object sender, EventArgs e)
    {
        string depId = this.QueryDepartment.SelectDepmanetId;
        string empId = SelUser.EmpName;
        string tiaojian = this.RadioButtonList1.SelectedValue;
        if (depId != "0")
            ViewState["depId"] = depId;
        if (empId != "")
            ViewState["empid"] = empId;
        if (tiaojian == "终止有效日期")
            ViewState["tiaojian"] = "终止有效日期";
        else
            ViewState["tiaojian"] = "复审日期";
        string year = this.DSelYearMonth1.SelectYear;
        string month = this.DSelYearMonth1.SelectMonth;
        if (year != "0" && month != "0")
            ViewState["dates"] = this.DSelYearMonth1.SelectYearMonth + "-01";
        else if (year == "0" && month != "0" || year != "0" && month == "0")
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "", "alert('选择年份和月份')", true);
            ViewState.Clear();
            return;
        }

        InitializeComponent();
        Master.DataSource = WMaster;

        ViewState.Clear();

    }


}
